home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / 第1特集Plug-in / Photoshop / LYNXX Plug-In Folder.sit / LYNXX Plug-In Folder / LYNXXfiles.c < prev    next >
Text File  |  1993-10-24  |  3KB  |  130 lines

  1. /*********************************************************************
  2.  
  3.     File saving exercise
  4.     
  5. *********************************************************************/
  6.     
  7. #include "LYNXX.h"
  8. #include "LYNXXfiles.h"
  9.  
  10. extern SFReply     reply;
  11. extern TPermanent gPermanent;
  12. extern AcquireRecordPtr gStuff;
  13.  
  14. static Point     SFGwhere = { 90, 82 };
  15. static Point     SFPwhere = { 106, 104 };
  16.  
  17. int GetRawImage (short_H TheImage)
  18. {
  19.     int     vRef,refNum,io;
  20.     Str255    fn;
  21.             
  22.             if (OldFile(fn, &vRef ))
  23.                 if (FSOpen(fn, vRef, &refNum)==noErr) {
  24.                     
  25.                         if (ReadFile(refNum)==noErr) {
  26.                             pStrCopy(reply.fName,gStuff->filename);
  27.                             gStuff->vRefNum = vRef;
  28.                             }
  29.                             
  30.                         }
  31.                     if (FSClose(refNum)==noErr) ;
  32.                     
  33.                 else FileError("¥pError opening ", fn);
  34. }
  35.  
  36.  
  37. int OldFile (Str255 fn, int *vRef)
  38.  
  39. {
  40.     
  41.     SFTypeList        myTypes;
  42.     extern SFReply     reply;
  43.     
  44.     myTypes[0]='TEXT';
  45.  
  46.     SFGetFile(SFGwhere, "¥p", 0L, 1, myTypes, 0L, &reply );
  47.  
  48.     if (!reply.good)
  49.         return (0);
  50.     else {
  51.         pStrCopy(reply.fName, fn);
  52.         *vRef = reply.vRefNum;
  53.         return(1);
  54.     }
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. int ReadFile (int refNum)
  62.  
  63. {
  64.     long            DATASize;
  65.     long             j,k;
  66.     int                ioerror;
  67.     unsigned char     tempdata[288],rawbyte1,rawbyte2,rawbyte3;
  68.     short            MinData,MaxData;
  69.     short             tempshort;
  70.     short            **TheImage;
  71.     
  72.     DATASize = 288;
  73.     MaxData = 0;
  74.     MinData = 4096;
  75.     
  76.     TheImage = gPermanent.MyImageHandle;
  77.     
  78.     for (j=0;j<NUMROW;j++)
  79.     {                               
  80.     if (FSRead(refNum,&DATASize,(Ptr)tempdata) != noErr)
  81.             ioerror = 1;
  82.         else { ioerror = 0;
  83.                 for (k=0;k<96;k++)
  84.                     {
  85.                     rawbyte1 = tempdata[k*3];                        /* The heart of the file translation  */
  86.                     rawbyte2 = tempdata[k*3 + 1];                    /* bit blighting gets the 12 bit data */                                
  87.                     rawbyte3 = tempdata[k*3 + 2];                    /* into 16 bit words                  */
  88.                     
  89.                     tempshort = ((rawbyte2 & 0x000F)<<8)+rawbyte1;
  90.                     *((*TheImage)+j*NUMCOL+2*k) = tempshort;
  91.                     if (tempshort>=MaxData) MaxData = tempshort; 
  92.                     if (tempshort<=MinData) MinData = tempshort;
  93.                     
  94.                     tempshort = ((rawbyte2 & 0x00F0)<<4)+rawbyte3;
  95.                     *((*TheImage)+j*NUMCOL+2*k+1) = tempshort;
  96.                     if (tempshort>=MaxData) MaxData = tempshort; 
  97.                     if (tempshort<=MinData) MinData = tempshort;
  98.                     }
  99.             }
  100.             
  101.     }
  102.     if (ioerror !=1)
  103.         { 
  104.           gPermanent.maxImageValue = MaxData;
  105.           gPermanent.minImageValue = MinData;
  106.         }
  107.     return ioerror;
  108.             
  109. }
  110.  
  111.  
  112.  
  113. int pStrCopy (StringPtr p1, StringPtr p2)
  114.  
  115. /* copies a pascal string from p1 to p2 */
  116. {
  117.     register int len;
  118.     
  119.     len = *p2++ = *p1++;
  120.     while (--len>=0) *p2++=*p1++;
  121. }
  122.  
  123.  
  124. int FileError(Str255 s, Str255 f)
  125.  
  126. {
  127.     ParamText(s, f,"¥p", "¥p");
  128.     Alert(256, 0L);
  129. }
  130.